<?php

/**
 * @author: biggege
 * @since:  2021-09-10 16:50:47
 */

namespace App\Http\Services\Manage;


use Maatwebsite\Excel\Concerns\FromArray;

class ExportDataService implements FromArray
{

    protected $list;

    public function __construct($data, array $columns)
    {
        $list = [];
        $list[] = array_values($columns);

        $params = array_keys($columns);

        foreach ($data as $item) {
            $tempArr = [];
            foreach ($params as $param) {
                $tempArr[] = $item[$param] ?? '';
            }
            $list[] = $tempArr;
        }

        $this->list = $list;
    }

    public function array(): array
    {
        return $this->list;
    }
}